import React, { Component, PureComponent } from 'react'
import axios from 'axios';
export default class MovieShow extends PureComponent {
  state={
    list:[]
  }
  componentDidMount(){
    console.log('-----componentDidMount-------',this.props.type);
  }
  /*
    当父组件传递进来的props值发生变化后，可以触发componentWillReceiverProps钩子函数
  */
  componentWillReceiveProps(){
    console.log('-----componentDidUpdate-------',this.props.type);
    switch(this.props.type){
        case 1:
            this.getMovieHot()
            break;
        case 2:
            this.getMovieComming()
            break;
        default:
            break;
    }
  }
  getMovieHot=async()=>{
    let result=await axios.get('https://www.fastmock.site/mock/4441a79ad5f884f83b784cf4c588bdb6/movies/getHotMovies')
    this.setState({
        list:result.data.movies
    })
  }
  getMovieComming=async()=>{
    let result=await axios.get('https://www.fastmock.site/mock/4441a79ad5f884f83b784cf4c588bdb6/movies/getUpCommingMovies')
    this.setState({
        list:result.data.movies
    })
  }
  render() {
    return (
      <div>
         <ul>
            {
                this.state.list.map((item,index)=><li key={index}>{item.title}</li>)
            }
         </ul>
      </div>
    )
  }
}
